<?PHP
header("Content-Type: text/html; charset=utf-8");
include_once 'public/DB_Oracle.php';
$DBsql = new DB_Oracle ();

if(isset($_GET['option'])&&$_GET['option']=="add"){
$sql="update loc_number t set t.number_id='".$_GET['num']."'";
if($DBsql->query($sql)){
	echo "<script language='javascript'>alert('修改成功');window.location.href='listen1.php';</script>";
	}else{
	echo "<script language='javascript'>alert('修改失败');window.location.href='listen1.php';</script>";}
	}




		$sql="select * from loc_number t";
	$arr1=$DBsql->fetch_all_array($sql);
if(isset($_POST['option'])&&$_POST['option']=='post'){
	$str=explode(";",$_POST['str']);
	if($str[count($str)-1]==''){
		$str=implode(',',$str);
		$str=substr($str,0,strlen($str)-1);
		}else{
			$str=implode(',',$str);
			}
	$sql="select t.sim from dep_vehicle t where t.license_plate in('".$str."')";
    $arr=$DBsql->fetch_all_array($sql);
	$phoneNo='';
if(count($arr)!=0){
	for($i=0;$i<count($arr);++$i){
		$phoneNo.=$arr[$i]['SIM'].',';
		}
	}
	$phoneNo=substr($phoneNo,0,strlen($phoneNo)-1);
try{
$ws = "http://192.168.20.211:8088/pgis/services/meeting?wsdl";
$client = new SoapClient ( $ws );
$GLOBALS['client'] = $client;
}
catch (Exception $e){
	exit(102);
}       
if(isset($_POST['a'])){
		$sql="select * from loc_number t";
	$arr1=$DBsql->fetch_all_array($sql);
		$resu = convokeMeeting($arr1[0]['NUMBER_ID'],$phoneNo);
		echo $resu . "," . $GLOBALS['number'];
		exit();
		}else{
		endMeeting($_POST['b']);
		}
	exit();
	}
	function convokeMeeting($a,$honeNo) {
	$resu = $GLOBALS['client']->convokeMeeting ( '110',''.$a.'',$honeNo);
	$resu = explode ( "||", $resu );
	if ($resu [0] == 100) {
		$GLOBALS['number'] = $resu [1];
		return $resu [0];
	} else {
		return $resu [0];
	}
}
	
function endMeeting($b) {
	$resu = $GLOBALS['client']->endMeeting ($b);
	$resu = explode ( "||", $resu );
	if ($resu [0] == 100) {
		echo "Y";
	} else {
		echo "N";
	}
}
?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/validform.css" rel="stylesheet" type="text/css" />
<link href="public/page/css/css.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="js/public.js"></script>
<script language="javascript">
	function ADD(){
		           if(document.getElementById("add").value==""){
			   alert("请检查你输入是否正确");
			   return false;
			   }
			   var li=/^\d{6,15}$/;
		   if(!li.test(document.getElementById("add").value)){
			   alert("请检查你输入是否正确");
			   return false;
			   }
	var url="listen1.php?"+encodeURI("option=add&num="+document.getElementById("add").value);
	window.location=url;  
		}
	
var af;
function abc(){
	if(document.getElementById('abc').value==''){
		alert("输入车辆信息不能为空");
		return 0;
		}
	if(document.getElementById('f').value=="通话"){
		var li=/[^\u4E00-\u9FA5\;\w\d]$/;
		var str=document.getElementById('abc').value;
		if(li.test(str)){
			alert("不正确");
			return 0;
			}
	$.ajax({
			type:"POST",
			url:"listen1.php",
			cache:false,
			data:"a=1&option=post&str="+str,
			success:function(data){
				var arr=data.split(',');
				if(arr[0]==100){
					document.getElementById('f').value="挂断";
					af=arr[1];
					}else{
						alert("拨打失败");
						}
					}
		});}
		else{
			$.ajax({
			type:"POST",
			url:"listen1.php",
			cache:false,
			data:"option=post&str="+str+"&b="+af,
			success:function(data){
				if(data=="Y"){
					document.getElementById('f').value="通话";
					}else{
						alert("挂断失败");
						}
					}
		});
			}
	}
</script>
<!--管理列表开始-->
<div class="manageTab" style="margin-top:0px;">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="usrTab">
    <tr>
      <td width="8" height="25"><img src="images/user_01.jpg" height="25" width="8" /></td>
      <td style="background:#3980b2;" valign="middle" height="16" ><div class="use_righgDiv"><span  style="width:100px"><img src="images/001.gif" height="14" width="14" /><a href="javascript:void(null)" onclick="javascript:POPdiv('POPdiv')">设置主叫号码</a></span></div>
        <div class="use_leftDiv">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td  width="22"><img src="images/311.gif" height="16" width="16" /></td>
              <td align="left"><span class="tdTit">要通话的车辆</span></td>
            </tr>
          </table>
        </div></td>
      <td width="8" height="25"><img src="images/user_02.gif" height="25" width="8" /></td>
    </tr>
    <tr>
      <td style="background:#3980b2;" >&nbsp;</td>
      <td><table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" class="usrList" id="List">
          <tr>
            <td  class="td90b2">输入车辆信息</td>
            <td  class="td90b2">提交</td>
          </tr>
	          <tr>
	            <td class="tdfff"><textarea  style="width:300px"  id="abc"></textarea>车辆之间以分号隔开</td>
                <td class="tdfff"><input type="button" id="f" onclick="abc()" value="通话" /></td>
	          </tr>
          <tr>
            <td colspan="10" class="tdfff">&nbsp;</td>
          </tr>
        </table></td>
      <td style="background:#3980b2;">&nbsp;</td>
    </tr>
    <tr>
      <td height="24" width="8"><img src="images/user_03.gif" height="24" width="8" /></td>
      <td style="background:#3980b2;">
    </td>
      <td height="24" width="8"><img src="images/user_04.gif" height="24" width="8" /></td>
    </tr>
  </table>
</div>
<!--管理列表结束-->


<!--弹出层开始-->
<div id="POPdiv" class="POPdiv">
  <div class="POPdiv_top"><a href="javascript:void(null)" onclick="ClosePOPdiv('POPdiv')"><img src="images/ico_close.jpg" alt="关闭" /></a>号码设置</div>
  <div class="POPdiv_content">
    <form action="" method="post">
     <table border="0" cellpadding="5" cellspacing="0">
                <tr>
			      <td width="80"><label >主叫号码：</label></td>
			      <td><input type="text" id="add" value="<?PHP echo $arr1[0]['NUMBER_ID'];?>"/></td>
			      <td><span class="Validform_checktip">输入主叫号码</span></td>
			    </tr>
                <tr>
			      <td colspan="3"><input id="up" type="button" class="btnbg" onclick="ADD()" value="更新号码" style="width:100px; margin-left:80px; color:#FFF" /></td>
			    </tr>
			  </table>
    </form>
  </div>
</div>
<!--弹出层结束-->